import conf from '../../config';
import Http from '../http';

const baseUrl = conf.interface.baseUrl;

// 登录
export const loginApi = async (params, contentType) => {
  const url = `${baseUrl}/wx/login`;
  const res = await Http.post(url, params, contentType);
  return res.data || {};
};
// 微信用户首次注册登录
export const registAndBind = async (params, contentType) => {
  const url = `${baseUrl}/wx/registAndBind`;
  const res = await Http.post(url, params, contentType);
  return res.data || {};
};
// 微信用户经销商绑定账号
export const bindLoginName = async (params, contentType) => {
  const url = `${baseUrl}/userLogin/bindLoginName`;
  const res = await Http.post(url, params, contentType);
  return res.data || {};
};
// 微信用户学校用户绑定地址
export const userAddAddress = async (params, contentType) => {
  const url = `${baseUrl}/userAddress/addAddress`;
  const res = await Http.post(url, params, contentType);
  return res.data || {};
};
// 微信用户学校用户添加地址时候请求学校列表
export const getNearbySchools = async (params, contentType) => {
  const url = `${baseUrl}/school/getNearbySchools`;
  const res = await Http.get(url, params, contentType);
  return res.data || {};
};
// 订单列表
export const listByLoginUser = async (params) => {
  const url = `${baseUrl}/order/listByLoginUser`;
  const res = await Http.get(url, params);
  return res.data || {};
};
// 创建订单
export const addOrder = async (params) => {
  const url = `${baseUrl}/order/addOrder`;
  const res = await Http.post(url, params);
  return res.data || {};
};
// 订单报价
export const updatePrice = async (params) => {
  const url = `${baseUrl}/order/updatePrice`;
  const res = await Http.post(url, params);
  return res.data || {};
};
// 同意报价
export const agreePrice = async (params) => {
  const url = `${baseUrl}/order/agreePrice`;
  const res = await Http.post(url, params);
  return res.data || {};
};
// 供销商处理完成订单
export const completeOrder = async (params) => {
  const url = `${baseUrl}/order/completeOrder`;
  const res = await Http.post(url, params);
  return res.data || {};
};
// 学校处理验收订单
export const checkOrder = async (params) => {
  const url = `${baseUrl}/order/checkOrder`;
  const res = await Http.post(url, params);
  return res.data || {};
};
// 订单详情
export const getOrderInfo = async (params) => {
  const url = `${baseUrl}/order/getOrderInfo/${params.id}`;
  console.log('url', url)
  const res = await Http.get(url);
  return res.data || {};
};
// 供销商订单统计详情
export const dealerOrders = async (params) => {
  const url = `${baseUrl}/order/dealerOrders`;
  const res = await Http.get(url, params);
  return res.data || {};
};
// 学校列表
export const getAllSchools = async (params) => {
  const url = `${baseUrl}/school/list`;
  const res = await Http.get(url, params);
  return res.data || {};
};
// 添加地址
export const addAddress = async (params) => {
  const url = `${baseUrl}/address/addAddress`;
  const res = await Http.post(url, params);
  return res.data || {};
};
// 地址列表
export const addressList = async (params) => {
  const url = `${baseUrl}/userAddress/list`;
  const res = await Http.get(url, params);
  return res.data || {};
};
// 注销登录
export const logout = async (params) => {
  const url = `${baseUrl}/userLogin/logout`;
  const res = await Http.post(url);
  return res.data || {};
};
// 签约学校（经销商）
export const listBySign = async (params) => {
  const url = `${baseUrl}/school/listBySign`;
  const res = await Http.get(url);
  return res.data || {};
};
// 保存订阅消息状态
export const saveSubscribeStatus = async (params) => {
  const url = `${baseUrl}/wx/saveSubscribeStatus`;
  const res = await Http.post(url, params);
  return res.data || {};
};
//获取用户信息
export const getDealerByToken = async () => {
  const url = `${baseUrl}/userLogin/getDealer`;
  const res = await Http.get(url);
  return res.data || {};
};

export const schoolListByLoginUser = async (params) => {
  const url = `${baseUrl}/school/listBySign`;
  const res = await Http.get(url, params);
  return res.data || {};
};

export const updateAvatarUrl = async (params) => {
  const url = `${baseUrl}/wx/updateUserInfo`;
  const res = await Http.post(url, params);
  return res.data || {};
};
export const knowledgeListUrl = async (params) => {
  const url = `${baseUrl}/knowledge/list`;
  const res = await Http.get(url, params);
  return res.data || {};
};
export const getKnowledgeInfo = async (params) => {
  const url = `${baseUrl}/knowledge/${params.id}`;
  console.log('url', url)
  const res = await Http.get(url);
  return res.data || {};
};
export const answersListUrl = async (params) => {
  const url = `${baseUrl}/answers/list`;
  const res = await Http.get(url, params);
  return res.data || {};
};
export const getAswersInfo = async (params) => {
  const url = `${baseUrl}/answers/${params.id}`;
  console.log('url', url)
  const res = await Http.get(url);
  return res.data || {};
};